'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 掠夺
 * @author sundbcn@gmail.com (sun debing)
 */

var dataApi = require('../libs/dataApi');

/**
 * 获取vip等级配置
 * @param  {[type]} vip [description]
 * @return {[type]}     [description]
 */
exports.getConf = function (vip) {
    return _getConf(vip);
};

/**
 * 根据vip获取逆袭副本
 * @param  {[type]} vip [description]
 * @return {[type]}     [description]
 */
exports.getRebelByVip = function (vip) {
    var vip_lv_conf = _getConf(vip);
    if (!vip_lv_conf) {
        console.error('vip_lv_conf type can not found:' + vip);
        return 0;
    }
    return vip_lv_conf.rebel_difficult;
};

/**
 * 根据vip获取购买金币的次数
 * @param  {[type]} vip [description]
 * @return {[type]}     [description]
 */
exports.getCanBuyGoldMaxNum = function (vip) {
    var vip_lv_conf = _getConf(vip);
    if (!vip_lv_conf) {
        console.error('vip_lv_conf type can not found:' + vip);
        return 0;
    }
    return vip_lv_conf.buy_gold_times;
};

/**
 * 根据vip获取购买金币的次数
 * @param  {[type]} vip [description]
 * @return {[type]}     [description]
 */
exports.getCanBuyFoodMaxNum = function (vip) {
    var vip_lv_conf = _getConf(vip);
    if (!vip_lv_conf) {
        console.error('vip_lv_conf type can not found:' + vip);
        return 0;
    }
    return vip_lv_conf.buy_food_times;
};

/**
 * 根据vip获取购买体力的次数
 * @param  {[type]} vip [description]
 * @return {[type]}     [description]
 */
exports.getCanBuySpMaxNum = function (vip) {
    var vip_lv_conf = _getConf(vip);
    if (!vip_lv_conf) {
        console.error('vip_lv_conf type can not found:' + vip);
        return 0;
    }
    return vip_lv_conf.buy_sp_times;
};

/**
 * 根据vip获取购买精力的次数
 * @param  {[type]} vip [description]
 * @return {[type]}     [description]
 */
exports.getCanBuyEnergyMaxNum = function (vip) {
    var vip_lv_conf = _getConf(vip);
    if (!vip_lv_conf) {
        console.error('vip_lv_conf type can not found:' + vip);
        return 0;
    }
    return vip_lv_conf.buy_energy_times;
};

exports.getCanBuyApMaxNum = function (vip) {
    var vip_lv_conf = _getConf(vip);
    if (!vip_lv_conf) {
        console.error('vip_lv_conf type can not found:' + vip);
        return 0;
    }
    return vip_lv_conf.buy_ap_times;
};

/**
 * 根据掠夺购买次数获取消耗钻石数量
 * @param  {[type]} times [description]
 * @return {[type]}       [description]
 */
exports.getSubDiamondNum = function (times) {
    var pvp_times_conf = _getPvpTimesConf(times);
    if (!pvp_times_conf) {
        return 50;
    }
    return pvp_times_conf.cost_point;
};

/**
 * 获取vip免费建筑时间
 * @param  {[type]} times [description]
 * @return {[type]}       [description]
 */
exports.getBuildFreeTime = function (vip) {
    var conf = _getConf(vip);
    if (!conf) {
        console.error('invalid vip:', vip);
        return 0;
    }
    return conf.building_free_time;
};

var _getPvpTimesConf = function (times) {
    return dataApi.pvp_times.findById(times);
};

var _getConf = function (vip) {
    return dataApi.vip_lvl.findById(vip + 1);
};
